﻿using System;
using System.Text.Json;
using Aliyun.Acs.Core;

namespace ARC.AliYun.SMSService.Service
{
    public class BaseAliyun
    {
        protected IAcsClient _client;
        /// <summary>
        /// 创建参数模板
        /// </summary>
        /// <returns></returns>
        protected CommonRequest CreateCommonRequest()
        {
            return new CommonRequest();
        }
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        protected CommonResponse SendRequest(CommonRequest request)
        {
            try
            {
                return _client.GetCommonResponse(request);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
           
        }

        /// <summary>
        /// 反序列化返回结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        protected T Json<T>(CommonRequest request)
        {
            var data = SendRequest(request).Data;
            return JsonSerializer.Deserialize<T>(data);
        }
    }
}
